package com.kk.base.dao.home;

import com.kk.base.entity.home.HomeUserAddress;
import com.kk.base.entity.home.HomeUserTypeEnum;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @info : 用户地址数据库处理层
 */
@Repository
public interface HomeUserAddressDao extends JpaRepository<HomeUserAddress, Long>, JpaSpecificationExecutor<HomeUserAddress> {

    /**
     * 通过用户名查找
     * @param name
     * @return
     */
    HomeUserAddress findByName(String name);

    /**
     * 通过手机号查找
     * @param mobile
     * @return
     */
    HomeUserAddress findByMobile(String mobile);


    /**
     * 通过id查找
     * @param id
     * @return
     */
    @Query("select hua from HomeUserAddress hua where id = :id")
    HomeUserAddress find(@Param("id")Long id);


    /**
     * 通过用户ID是否是默认地址查找
     * @param isDefault
     * @return
     */
    HomeUserAddress findByIsDefaultAndHomeUserTypeAndHomeUser_Id(Integer isDefault, HomeUserTypeEnum homeUserType,Long homeUserId);

    /**
     * 通过当前登录用户和类型查询
     * @param homeUserType
     * @param userId
     * @return
     */
    List<HomeUserAddress> findByHomeUserTypeAndHomeUser_Id(HomeUserTypeEnum homeUserType,Long userId);

}
